package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;

public class ROUNDDOWN extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 2)
      return Primitive.ERROR_NAME;
    Object localObject1 = paramArrayOfObject[0];
    Object localObject2 = paramArrayOfObject[1];
    double d = 1.0D;
    if ((localObject1 instanceof Number) && (localObject2 instanceof Number))
    {
      if (((Number)localObject2).intValue() < 0)
      {
        for (i = 1; i <= -1 * ((Number)localObject2).intValue(); ++i)
          d *= 10.0D;
        if (((Number)localObject1).doubleValue() >= 0.0D)
          return new Double(()(((Number)localObject1).doubleValue() / d) * d);
        return new Double(()(((Number)localObject1).doubleValue() / d) * d);
      }
      if (((Number)localObject2).intValue() == 0)
      {
        if (((Number)localObject1).doubleValue() >= 0.0D)
          return new Long(()((Number)localObject1).doubleValue());
        return new Long(()((Number)localObject1).doubleValue());
      }
      for (int i = 1; i <= ((Number)localObject2).intValue(); ++i)
        d *= 10.0D;
      if (((Number)localObject1).doubleValue() >= 0.0D)
        return new Double(()(((Number)localObject1).doubleValue() * d) / d);
      return new Double(()(((Number)localObject1).doubleValue() * d) / d);
    }
    return Primitive.ERROR_NAME;
  }

  public Function.Type getType()
  {
    return Function.MATH;
  }

  public String getCN()
  {
    return "ROUNDDOWN(number,num_digits):靠近零值，向下（绝对值减小的方向）舍入数字。\nnumber:为需要向下舍入的任意实数。\nnum_digits:舍入后的数字的位数。\n函数 ROUNDDOWN 和函数 ROUND 功能相似，不同之处在于函数 ROUNDDOWN 总是向下舍入数字。\n示例:\nROUNDDOWN(3.2, 0) 等于 3\nROUNDDOWN(76.9,0) 等于 76\nROUNDDOWN(3.14159, 3) 等于 3.141\nROUNDDOWN(-3.14159, 1) 等于 -3.1\nROUNDDOWN(31415.92654, -2) 等于 31,400\n";
  }

  public String getEN()
  {
    return "ROUNDDOWN(number,num_digits): Rounds a number down, toward zero.\nNumber is any real number that you want rounded down.\nNum_digits is the number of digits to which you want to round number.\n\nROUNDDOWN behaves like ROUND, except that it always rounds a number down. \n\nExample:\n   ROUNDDOWN(3.2, 0) =  3\n   ROUNDDOWN(76.9,0) = 76\n   ROUNDDOWN(3.14159, 3) = 3.141\n   ROUNDDOWN(-3.14159, 1) = -3.1\n   ROUNDDOWN(31415.92654, -2) = 31,400\n";
  }
}